#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

struct Data
{
    string name;
    string zhiwei;
    long long banggong;
    short level;
    int index;
};

string zw_str[] = { "BangZhu", "FuBangZhu", "HuFa", "ZhangLao", "TangZhu", "JingYing", "BangZhong" };
int zw_remain[] = { 1, 2, 2, 4, 7, 25, 128 };
int crt_zw;

bool compare_bg(const Data &a, const Data &b)
{
    int i, j;
    if (a.zhiwei == "BangZhu")
        return true;
    if (b.zhiwei == "BangZhu")
        return false;
    if (a.zhiwei == "FuBangZhu" && b.zhiwei != "FuBangZhu")
        return true;
    if (b.zhiwei == "FuBangZhu" && a.zhiwei != "FuBangZhu")
        return false;    
    if (a.banggong == b.banggong)
    {
        i = j = 0;
        while (zw_str[i++] != a.zhiwei);
        while (zw_str[j++] != b.zhiwei);
        return i < j;
    }
    
    return a.banggong > b.banggong;
}

bool compare_zw(const Data &a, const Data &b)
{
    int i, j;
    i = j = 0;
    while (zw_str[i] != a.zhiwei) i++;
    while (zw_str[j] != b.zhiwei) j++;
    if (i != j)
        return i < j;

    return a.level > b.level;    
}

int main(int argc, char const *argv[])
{
    
    Data datas[124], results[124];
    int n;
    int i, j, k, zw_num;   
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> datas[i].name 
            >> datas[i].zhiwei
            >> datas[i].banggong
            >> datas[i].level;
        datas[i].index = i;
    }

    stable_sort(datas, datas + n, compare_bg);
    crt_zw = 2;
    for (i = 1; i < n && datas[i].zhiwei == "FuBangZhu"; i++);
    for (; i < n; i++)
    {
        if (!zw_remain[crt_zw])
        {
            crt_zw++;
        }
        datas[i].zhiwei = zw_str[crt_zw];
        zw_remain[crt_zw]--;
    }
    for (i = 0; i < n; i++)
    {
        results[datas[i].index] = datas[i];
    }

    stable_sort(results, results + n, compare_zw);

    for (i = 0; i < n; i++)
    {
        cout << results[i].name
            << " " 
            << results[i].zhiwei 
            << " " 
            << results[i].level 
            << "\n";
    }
    
    return 0;
}
